package main


import (
    "fmt"
)


type treeNode struct {
    value int
    left, right *treeNode
}


func createTreeNde(Value int) *treeNode {
    return &treeNode{value: Value}
}


func (node treeNode) Print() {
    fmt.Printf("%d", node.value)
}

func (node *treeNode) setValue(Value int) {
    if node == nil {
        fmt.Sprintf("node is NULL")
        return 
    }
    node.value = Value
}


func (node *treeNode) traverse() {
    node.TraverseFunc( func(n *treeNode){

        n.Print()
    })
    fmt.Println()
}


func (node *treeNode) TraverseFunc(f func(*treeNode)) {
    if node == nil {
        return 
    }

    node.left.TraverseFunc(f)
    f(node)
    node.right.TraverseFunc(f)
}



func main(){
    var root treeNode

    root = treeNode{value: 3}
    root.left = &treeNode{value: 0}// root.left = &treeNode{}
    root.right = &treeNode{5, nil, nil}
   
    root.left.right = createTreeNde(2)
    
    
    root.right.left = new(treeNode)
    root.right.left.setValue(4)

    root.traverse()
    
    nodeCount := 0
    root.TraverseFunc(func(node *treeNode) {
        nodeCount++
    })
    fmt.Println("nodeCount:", nodeCount)
}

